package com.mybatis.controller;

import com.mybatis.entity.Employee;
import com.mybatis.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    /**
     * 查询员工数据
     *
     * @return
     */
    @GetMapping("/select")
    public List<Employee> select() {
        List<Employee> list = employeeService.list();
        return list;
    }

    /**
     * 通过id删除员工
     *
     * @param id
     */
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable Integer id) {
        employeeService.delete(id);
    }

    @PostMapping("/insert")
    public void insert(@RequestBody Employee employee) {
        employeeService.save(employee);
    }

    @GetMapping("/{id}")
    public int getById(@PathVariable Integer id) {
        int gid = employeeService.getById(id);
        return gid;
    }

    @PostMapping("/update")
    public void update(@RequestBody Employee employee) {
        employeeService.remove(employee);

    }
}
